package com.stargate.bd.bean;

import java.sql.Date;


public class FormatDate {

	public static java.sql.Date javaToSQL(java.util.Date dateJava) {
		return new Date(dateJava.getTime());
	}

	
	@SuppressWarnings("deprecation")
	public static java.util.Date sqlToJava(java.sql.Date dateSQL) {
		return new java.util.Date(dateSQL.getYear(), dateSQL.getMonth(), dateSQL.getDay());
	}

	/**
	 * 
	 * @param dateString - date au format jj/mm/aaaa
	 * @return une date de type java.sql.Date
	 */
	@SuppressWarnings("deprecation")
	public static java.sql.Date stringToSQL(String dateString) {
		String split[] = dateString.split("/");
		java.util.Date dateJava = new java.util.Date(Integer.valueOf(split[2]),
				Integer.valueOf(split[1]), Integer.valueOf(split[0]));
		return javaToSQL(dateJava);
	}
	
	/**
	 * 
	 * @param dateString - date au format jj/mm/aaaa
	 * @return une date de type java.util.Date
	 */
	@SuppressWarnings("deprecation")
	public static java.util.Date stringToJava(String dateString) {
		String split[] = dateString.split("/");
		return new java.util.Date(Integer.valueOf(split[2]),
				Integer.valueOf(split[1]), Integer.valueOf(split[0]));
	}
	
	public static boolean isStringFormat(String dateString) {
		return dateString.split("/").length == 3;
	}
	
	public static java.util.Date dateSystemJava() {
		return new java.util.Date();
	}
	
	public static java.sql.Date dateSystemSQL() {
		return new java.sql.Date(dateSystemJava().getTime());
	}
}
